package com.xintai.system.controller;

import java.util.List;

import com.xintai.utils.StaticString;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xintai.common.annotation.Log;
import com.xintai.common.core.controller.BaseController;
import com.xintai.common.core.domain.AjaxResult;
import com.xintai.common.enums.BusinessType;
import com.xintai.system.domain.ErpKuwei;
import com.xintai.system.service.IErpKuweiService;
import com.xintai.common.utils.poi.ExcelUtil;
import com.xintai.common.core.page.TableDataInfo;

/**
 * 库位Controller
 * 
 * @author xintai
 * @date 2020-12-29
 */
@RestController
@RequestMapping("/system/kuwei")
public class ErpKuweiController extends BaseController
{
    @Autowired
    private IErpKuweiService erpKuweiService;

    /**
     * 查询库位列表
     */
    @PreAuthorize("@ss.hasPermi('system:kuwei:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpKuwei erpKuwei)
    {
        System.out.println(erpKuwei);
        List<ErpKuwei> list = erpKuweiService.selectErpKuweiList(erpKuwei);
        return getDataTable(list);
    }

    /**
     * 导出库位列表
     */
    @PreAuthorize("@ss.hasPermi('system:kuwei:export')")
    @Log(title = "库位", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ErpKuwei erpKuwei)
    {
        List<ErpKuwei> list = erpKuweiService.selectErpKuweiList(erpKuwei);
        ExcelUtil<ErpKuwei> util = new ExcelUtil<ErpKuwei>(ErpKuwei.class);
        return util.exportExcel(list, "kuwei");
    }

    /**
     * 获取库位详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:kuwei:query')")
    @GetMapping(value = "/{kuweiId}")
    public AjaxResult getInfo(@PathVariable("kuweiId") Integer kuweiId)
    {
        return AjaxResult.success(erpKuweiService.selectErpKuweiById(kuweiId));
    }

    /**
     * 新增库位
     */
    @PreAuthorize("@ss.hasPermi('system:kuwei:add')")
    @Log(title = "库位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpKuwei erpKuwei)
    {
        if (erpKuweiService.verifyErpKuWei(erpKuwei))
            return AjaxResult.error(StaticString.NameRepeat(erpKuwei.getKuweiName()));
        return toAjax(erpKuweiService.insertErpKuwei(erpKuwei));
    }

    /**
     * 修改库位
     */
    @PreAuthorize("@ss.hasPermi('system:kuwei:edit')")
    @Log(title = "库位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpKuwei erpKuwei)
    {
        if (erpKuweiService.verifyErpKuWei(erpKuwei))
            return AjaxResult.error(StaticString.NameRepeat(erpKuwei.getKuweiName()));
        return toAjax(erpKuweiService.updateErpKuwei(erpKuwei));
    }

    /**
     * 删除库位
     */
    @PreAuthorize("@ss.hasPermi('system:kuwei:remove')")
    @Log(title = "库位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{kuweiIds}")
    public AjaxResult remove(@PathVariable Integer[] kuweiIds)
    {
        return toAjax(erpKuweiService.deleteErpKuweiByIds(kuweiIds));
    }
}
